#include<iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<string.h>
#include<unistd.h>
#include<string>

using namespace std;
const char* path=".bit";
mode_t mode=0664;

int main()
{
    int fd=open(path,O_RDWR|O_CREAT,mode);     //文件可读可写打开
    if(fd<=0)
    {
        close(fd);
        perror("open");
    }
    
    //向文件中写入i like linux!
    // char buff[1024];
    // cin>>buff;
    string buff;
    getline(cin,buff);
    // sprintf(buff,"%s\n","i like linux!");
    ssize_t w=write(fd,buff.c_str(),strlen(buff.c_str()));
    if(w<0)
    {
        close(fd);
        perror("write");
    }
    lseek(fd,0,SEEK_SET);
    char show[1024];
    ssize_t r=read(fd,show,sizeof(show)-1);   //读文件
    if(r>0)
    {
        show[r]='\0';
    }
    cout<<show<<endl;

    //关闭文件
    close(fd);
   
    return 0;
}